<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  const p1 = new Promise((resolve, reject) => {
    try {
      // throw new Error(`网络异常1`)
      console.log(`请求A数据`);
      setTimeout(() => {

        console.log(`请求A数成功`);
        // resolve(`ok`)
        resolve()
        // reject()
        // reject(`失败1`)
      }, 2000)
    } catch (e) {
      // console.log(e);
      // console.log(e.message);
      reject(e.message)
    }
  })
  // p1.then(()=>{},()=>{})

  //当调用finally的promsie实列还是pendding时 finally返回pedding的实列
  //当调用finally的promsie实列还是fullfield时 finally返回fullfield的实列 值为成功的实参
  //当调用finally的promsie实列还是reje时 finally返回rejected的实列 值为失败的实参
  //finally不改变promise实列的值 reason undefined
  //它会穿透 带着上一次promise实列的状态和值
  //理解 finally的返回值 和 调用finally的实列保持一致 证明P1和P2相同
  //当finally的回调函数中返回的是一个promise实列时，finall的返回值和这个promise实列保持一致
  //3如果FINALLY的回调函数里面发生报错 则返回状态为rejected的promis实列 值为错误信息


  const p2 = p1.finally((reason) => {
    // co  nsole.log(11);
    // console.log(value);
    console.log(1);
    // console.log(`finally的参数`,reason); //undefined
    return new Promise((resolve, reject) => {
      // resolve()
      // reject()
    })
  })

  console.log(`p1`, p1);
  console.log(`p2`, p2);

</script>

</html>